from django.conf import settings
from itsdangerous import TimedJSONWebSignatureSerializer as TJS


def decode_token(access_token):
    tjs = TJS(settings.SECRET_KEY, 300)

    try:
        data = tjs.loads(access_token)
    except:
        raise Exception('错误的access_token')

    # 获取openid数据
    openid = data.get('openid')
    if not openid:
        raise Exception('access_token　失效')

    return openid
